package com.net.xpay.common.manager.impl.partner;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.manager.AbstractVersionedManager;
import com.net.xpay.common.dao.partner.PartnerCodeMapper;
import com.net.xpay.common.domain.partner.PartnerCode;
import com.net.xpay.common.manager.partner.PartnerCodeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
@ReadTransactional
public class PartnerCodeManagerImpl extends AbstractVersionedManager<PartnerCode> implements PartnerCodeManager{

    @Autowired
    private PartnerCodeMapper mapper;


    @Override
    protected BasicMapper<Long, PartnerCode> getMapper() {
        return mapper;
    }

    @Override
    public List<PartnerCode> listByPartnerId(Long partnerId) {
        Preconditions.checkArgument(partnerId != null);
        PartnerCode condition = new PartnerCode();
        condition.setPartnerId(partnerId);
        return listByCondition(condition, new ArrayList<>());
    }

    @Override
    public PartnerCode findByPma(String pma) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(pma));
        PartnerCode condition = new PartnerCode();
        condition.setPma(pma);
        return getByCondition(condition);
    }
}
